var httpTool = require('../..//utils/network.js');
var util = require('../../utils/util.js')
// pages/my/my.js
const app = getApp()
Page({
  data:{
    intro:{},
    perfectHistoryList:[],
    commentList: [{
      isHide: true
    }, {
      isHide: true
    }]
    
  }, // 弹出、隐藏评论框
  toEnroll:function(){
    // wx.navigateTo({
    //   url: '/pages/signup/signup',
    // })
    util.navigateTo( '/pages/toEnroll/toEnroll')
  },
  toDeveloping: function () {
    // util.fxAlert('开发小伙伴正在开发中，敬请期待!')
    // return;
  },
  //我想发起冠名城市申请
  toApplyNaming: function () {
    util.navigateTo( '/pages/startintro/startintro')
  },
  getPerfectHolidayInfo:function(){
    var that = this;
    var url = app.data.httpUrl + 'v1/vacation/getVacationInfo'
    httpTool.sendRequest(url, {}, '', function (res) {
      that.setData({
        intro: res.entity
      })
      console.log("bannerList:");
      console.log(res.list)
    }, function (error) {
      console.log("加载轮播图异常:", error);
    })
  },
  getPerfectHistoryList: function () {
    var that = this;
    var url = app.data.httpUrl + 'v1/vacation/getVacationListAll'
    httpTool.sendRequest(url, {}, '', function (res) {
      var list = res.list;
      var historyArr = new Array();
      var total = list.length;
      for(let n=0;n<total;n+=2){
        var subList = new Array();
        subList.push(list[n]);
        if(n+1<total){
          subList.push(list[n + 1]);
        }
        historyArr.push(subList);
      }
      that.setData({
        perfectHistoryList: historyArr
      })
      console.log("historyList:");
      console.log(historyArr)
    }, function (error) {
      console.log("加载往期回顾列表异常:", error);
    })
  },
  toggleComment: function (e) {
    let _index = e.currentTarget.dataset.index;
    this.data.commentList.forEach((item, index) => {
      let _key = 'commentList[' + index + '].isHide'
      this.setData({
        [_key]: _index == index ? !this.data.commentList[_index].isHide : true
      })
    })
  },
  // 划入空白区域隐藏评论框
  hideAllComment: function () {
    let _isRun = this.data.commentList.some((item) => {
      return !item.isHide
    })
    _isRun && this.data.commentList.forEach((item, index) => {
      let _key = 'commentList[' + index + '].isHide'
      this.setData({
        [_key]: true
      })
    })
  },
  dianZan: function () {
    console.log("点赞")
  },
  pingLun: function () {
    console.log("评论")
  },
  fenXiang: function () {
    console.log("分享")
  },
  onLoad:function(options){
    // 生命周期函数--监听页面加载
    this.getPerfectHolidayInfo();
    //往期历史
    this.getPerfectHistoryList();
  },
  onReady:function(){
    // 生命周期函数--监听页面初次渲染完成
    
  },
  onShow:function(){
    // 生命周期函数--监听页面显示
    
  },
  onHide:function(){
    // 生命周期函数--监听页面隐藏
    
  },
  onUnload:function(){
    // 生命周期函数--监听页面卸载
    
  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作
    
  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数
    
  },
  onShareAppMessage: function() {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  }
})
